package org.springcloud.wisdom.amusement.controller.sys;


import org.springcloud.wisdom.amusement.bean.ResponseData;
import org.springcloud.wisdom.amusement.controller.BaseController;
import org.springcloud.wisdom.amusement.entity.TeamRecordsEntity;
import org.springcloud.wisdom.amusement.service.serviceimp.TeamRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/sign2")
public class TeamRecordsController extends BaseController {
    @Autowired
    private TeamRecordsService recordsService;

    // 发起签到
    @PostMapping("/ok2")
    public ResponseData<Boolean> insertRecords(@RequestBody TeamRecordsEntity recordsEntity) {
        Integer teamid = recordsEntity.getTeamid();
        Integer nid = recordsEntity.getNid();
        boolean result = recordsService.insertRecordsAndAttendence(teamid, nid);
        return returnBoolean(result);
    }

    // 社员签到(一定要传id）
    @PutMapping("/success2")
    public ResponseData<Object> updateRecords(@RequestBody TeamRecordsEntity recordsEntity) {
        boolean success = recordsService.updateRecordStatus(recordsEntity);
        return returnObject(success ? "签到成功！" : "签到失败！");
    }

    // 获取个人签到记录
    @RequestMapping("/all2")
    public ResponseData<Object> getPage(@RequestParam("pageNum") int pageNum,
                                        @RequestParam("pageSize") int pageSize,
                                        @RequestParam("sid") String sid){
        return returnObject(recordsService.getAllRecords(pageNum, pageSize, sid));
    }
    // 获取一次活动的签到记录
    @RequestMapping("/all22")
    public ResponseData<Object> getPage2(@RequestParam("pageNum") int pageNum,
                                        @RequestParam("pageSize") int pageSize,
                                        @RequestParam("nid") Integer nid){
        return returnObject(recordsService.getAllRecords2(pageNum, pageSize, nid));
    }

    // 查看签到结果
    @GetMapping("/result2")
    public ResponseData<Object> getActiveCheckResult(Integer nid,Integer teamid) {
        return returnObject(recordsService.getActiveCheckResult(nid, teamid));
    }
    // 查看未签到人
    @GetMapping("/unrive")
    public ResponseData<Object> getUnArriveStudent(Integer nid,Integer teamid) {
        return returnObject(recordsService.getUnArriveStudent(nid, teamid));
    }
    // 查看社团公告
    @GetMapping("/notice2")
    public ResponseData<Object> getTeamNotice(Integer type) {
        return returnObject(recordsService.getTeamNotice(type));
    }
}